package com.fantasy.file;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import org.apache.poi.ss.formula.functions.T;

public class GetFolderAbsPath {

	public String getCodeSourcePath(Class<T> t) {
		String filePath = null;
		try {
			filePath = URLDecoder.decode(
					GetFolderAbsPath.class.getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8");
			filePath = filePath.substring(0, filePath.lastIndexOf("/"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return filePath;
	}
	
	public static String getFolderPath(String folderName){
		String res = getPath() + "/" + folderName + "/";
		return res.replace("//", "/").replace("/", "\\");
	}
	
	public static String getFilePath(String fileName){
		return getPath() + "/" + fileName;
	}

	public static String getPath() {
		String path = null;
		try {
			path = URLDecoder.decode(System.getProperty("user.dir") , "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println(path);
		return (path + "/").replace("//", "/").replace("/", "\\");
	}

	public static void main(String[] args) {
		System.out.println(getPath());
	}

}
